package com.y.fund.schedule.tasks;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.y.fund.service.CommService;
import com.y.fund.utils.StrUtil;

/** mysql 数据库保活  */
@Component
@ConditionalOnProperty(prefix = "spring.datasource.druid", name = "validationQuery")
public class KeepAliveMySQLTask {

	@Autowired
	CommService commService;
	
	@Value("${spring.datasource.druid.validationQuery}")
	private String validationQuery;
	
	public KeepAliveMySQLTask() {
		super();
	}
	
	/* fixedDelay表示上次调用结束后与下次调用之间的固定时间，单位是毫秒。 */
	@Scheduled(fixedDelay = 120000)
	public void keepAlive() {
		if(StrUtil.NotBlankIgnoreNullStr(validationQuery)) {
			commService.queryBySQL(validationQuery, null);
		}
		
	}

}
